﻿using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
using StockholmsStad.Utilities;
using StockholmsStad.Windows.UI.Modules.Maintenance.Interfaces;
using StockholmsStad.Windows.UI.Modules.Maintenance.Models;

namespace StockholmsStad.Windows.UI.Modules.Maintenance.Views
{
    /// <summary>
    /// Interaction logic for TabItemStatisticsView.xaml
    /// </summary>
    public partial class TabItemStatisticsView : IStatisticView
    {
        public TabItemStatisticsView()
        {
            InitializeComponent();
        }

        #region IStatisticView Members

        public StatisticsPresentationModel Model
        {
            get { return DataContext as StatisticsPresentationModel; }
            set { DataContext = value; }
        }

        #endregion

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            var link = new Hyperlink { TargetName = "_blank" };

            string strUri = SettingsUtility.GetAppSetting(Facade.Properties.Resources.ReportViewer);

            if (RadioButtonCouplesPerPeriod.IsChecked.HasValue && RadioButtonCouplesPerPeriod.IsChecked.Value)
            {
                strUri = strUri +
                         SettingsUtility.GetAppSetting(Facade.Properties.Resources.CouplesPerPeriodStatPath) +
                         "&" + SettingsUtility.GetAppSetting(Facade.Properties.Resources.UriCommand);

                link.NavigateUri = new Uri(strUri);

                //link.NavigateUri = new Uri("http://parvis.input.nu/ReportServer/Pages/ReportViewer.aspx?/Reports/CouplesPerPeriodStat&rs:Command=Render&FromDate=2009-01-01&ToDate=2010-01-01&Details=True");
            }
            if (RadioButtonTicketsPerMinister.IsChecked.HasValue && RadioButtonTicketsPerMinister.IsChecked.Value)
            {
                strUri = strUri +
                         SettingsUtility.GetAppSetting(Facade.Properties.Resources.TicketsPerMinisterStatPath) +
                         "&" + SettingsUtility.GetAppSetting(Facade.Properties.Resources.UriCommand);

                link.NavigateUri = new Uri(strUri);

                //link.NavigateUri = new Uri("http://parvis.input.nu/ReportServer/Pages/ReportViewer.aspx?/Reports/TicketsPerMinisterStat&rs:Command=Render&FromDate=2009-01-01&ToDate=2010-01-01&MinisterID=1");
            }
            if (RadioButtonCancelledBookings.IsChecked.HasValue && RadioButtonCancelledBookings.IsChecked.Value)
            {
                strUri = strUri +
                         SettingsUtility.GetAppSetting(Facade.Properties.Resources.CouplesCancelledBookingStatPath) +
                         "&" + SettingsUtility.GetAppSetting(Facade.Properties.Resources.UriCommand);

                link.NavigateUri = new Uri(strUri);

                //link.NavigateUri = new Uri("http://parvis.input.nu/ReportServer/Pages/ReportViewer.aspx?/Reports/MinisterService&rs:Command=Render&rc:Parameters=false&ministerId=1");
            }
            if (RadioButtonAbsentCouples.IsChecked.HasValue && RadioButtonAbsentCouples.IsChecked.Value)
            {
                strUri = strUri +
                         SettingsUtility.GetAppSetting(Facade.Properties.Resources.CouplesAbsentBookingStatPath) +
                         "&" + SettingsUtility.GetAppSetting(Facade.Properties.Resources.UriCommand);

                link.NavigateUri = new Uri(strUri);

                //link.NavigateUri = new Uri("http://parvis.input.nu/ReportServer/Pages/ReportViewer.aspx?/Reports/MinisterService&rs:Command=Render&rc:Parameters=false&ministerId=1");
            }

            Process.Start(link.NavigateUri.AbsoluteUri);
        }
    }
}
